package com.liuhao.ssm.util;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.beanutils.PropertyUtils;

/**
 * Created by liuHao on 2017/5/26.
 */
public class MapUtils {
    public MapUtils() {
    }

    public static String getString(Object param, String key) {
        Map<Object, Object> c = formatMap(param);
        Object v = c.get(key);
        return v == null ? "" : v.toString();
    }

    public static Integer getInteger(Object param, String key) {
        Map<Object, Object> c = formatMap(param);
        Object v = c.get(key);
        return Integer.valueOf(v != null && !"".equals(v.toString()) ? Integer.parseInt(v.toString(), 10) : 0);
    }

    private static Map formatMap(Object parameter) {
        Map m = new HashMap();
        if (!(parameter instanceof Map)) {
            try {
                m = PropertyUtils.describe(parameter);
            } catch (Exception var3) {
                ;
            }
        } else {
            m = (Map) parameter;
        }

        return (Map) m;
    }
}
